<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>formData上传</title>
</head>
<body>
    <h1>formData 上传</h1>
    <input id="file" type="file" value="请选择文件">
    <input type="button" value="上传" onclick="upload();">
    <script src="jquery.min.js"></script>
    <script>

        function upload(){

            debugger;
            var myFile = $("#file")[0].files[0];
            var formData = new FormData();
            formData.append("file", myFile);
            $.ajax({
                type: "POST",
                url: '/formData/upload',
                data: formData,
                contentType: false, //必须
                processData: false, //必须
                //dataType: "json",
                success: function(res){
                    console.log("success");
                    console.log(res);
                    //清空上传文件的值
                    alert("上传完成");
                    $('#file').val('');
                    //$('#success_image').attr('src', res.realPathList[0]);
                },
                error : function(res) {
                    console.log("error");
                    console.log(res);
                    //清空上传文件的值
                    //$('#btn1').val('');
                }
            })
        }
    </script>
</body>
</html>